#ifndef MAP_IMPL_CU
#define MAP_IMPL_CU


__global__ void 
mapInit_kernel(struct sortRecord *d_R, int beginPos, int delta, int rLen, struct sortRecord value)  
{
	const int by = blockIdx.y;
	const int bx = blockIdx.x;
	const int tx = threadIdx.x;
	const int ty = threadIdx.y;	
	const int tid=tx+ty*blockDim.x;
	const int bid=bx+by*gridDim.x;
	const int numThread=blockDim.x;
	const int resultID=(bid)*numThread+tid;
	for(int pos=resultID+beginPos;pos<rLen;pos+=delta)
	{
		d_R[pos]=value;
	}
	
}

void mapInit(struct sortRecord *d_R, int beginPos, int rLen, struct sortRecord value)
{
	int numThreadsPerBlock_x=256;
	int numThreadsPerBlock_y=1;
	int numBlock_x=512;
	int numBlock_y=1;
	int numThread=numBlock_x*numThreadsPerBlock_x;
	dim3  thread( numThreadsPerBlock_x, numThreadsPerBlock_y, 1);
	dim3  grid( numBlock_x, numBlock_y , 1);
	mapInit_kernel<<<grid,thread>>>(d_R, beginPos, numThread, rLen, value);
}



#endif

